import AsyncStorage from '@react-native-async-storage/async-storage';
import { historyData } from './testData';

export const storeSearchHistory = async (value?: string) => {
    try {
        let array = historyData
        if (value) {
            array.push(value)
        }
        const jsonValue = JSON.stringify(array);
        await AsyncStorage.setItem('history', jsonValue);
    } catch (e) {
        // saving error
    }
};
export const getHistoryData = async ():Promise<any[]> => {
    try {
        const value = await AsyncStorage.getItem('history');
        if (value !== null) {
            console.log('value', value)
            return JSON.parse(value);
        } else {
            return [];
        }
    } catch (e) {
        return [];

    }
};